﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ADShop.Models;
using System.Web.Mvc;
namespace ADShop.Repository
{
    public class Global
    {
        #region "Variable"
        public static Member LoginMember = new Member();
        public static OrderProduct _orderProduct = new OrderProduct();
        public static string Error;
        #endregion
        public static List<Slider> ListSlider()
        {
            EShopEntities1 adshop = new EShopEntities1();
            return adshop.Slider.ToList();
        }
        
        public static SelectList ListIDCat()
        {
            EShopEntities1 adshop = new EShopEntities1();
            return new SelectList(adshop.Category.ToList(), "IDCategory", "NameCategory", 0);
        }
        public static SelectList ListIDMember()
        {
            EShopEntities1 adshop = new EShopEntities1();
            return new SelectList(adshop.Member.ToList(), "IDPrivilege", "IDPrivilege", 0);
        }
        public static SelectList ListMember()
        {
            EShopEntities1 adshop = new EShopEntities1();
            return new SelectList(adshop.InfoMember.ToList(), "IDMember", "IDMember", 0);
        }
        public static SelectList ListMemberName()
        {
            EShopEntities1 adshop = new EShopEntities1();
            return new SelectList(adshop.InfoMember.ToList(), "IDMember", "UserEmail", 0);
        }
        public static SelectList ListIDPri()
        {
            EShopEntities1 adshop = new EShopEntities1();
            return new SelectList(adshop.Privilege.ToList(), "IDPrivilege", "IDPrivilege", 0);
        }
        public static SelectList ListIDC()
        {
            EShopEntities1 adshop = new EShopEntities1();
            return new SelectList(adshop.Category.ToList(), "IDCategory", "NameCategory", 0);
        }
        public static List<Category> ListCategory()
        {
            EShopEntities1 adshop = new EShopEntities1();
            return adshop.Category.ToList();
        }
        public static List<Product> ListLatestProduct()
        {
            EShopEntities1 adshop = new EShopEntities1();
            return adshop.Product.Take(5).ToList();
        }
        public static List<Product> ListProductBest()
        {
            EShopEntities1 adshop = new EShopEntities1();
            return adshop.Product.OrderByDescending(d => d.View).Take(5).ToList();
        }
        
        public static byte[] EncryptData(string data)
        {
            System.Security.Cryptography.MD5CryptoServiceProvider md5Hasher = new System.Security.Cryptography.MD5CryptoServiceProvider();
            byte[] hashedBytes;
            System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
            hashedBytes = md5Hasher.ComputeHash(encoder.GetBytes(data));
            return hashedBytes;
        }
        public static string MD5(string data)
        {
            return BitConverter.ToString(EncryptData(data)).Replace("-", "").ToLower();
        }

        
    }
}